package edu.ccut.saturn.studio.wfg.xml.loader;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.wfg.model.Shape;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnEndNode;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnName;

public class SaturnEndNodeLoader extends NodeLoader {

	@Override
	public List<Shape> loadNodes(Element root) {
		NodeList endNodes = root.getElementsByTagName(SaturnName.XML_NAME);
		List<Shape> endList = new ArrayList<Shape>();
		for(int i = 0 ; i<endNodes.getLength();i++){
			Node end = endNodes.item(i);
			if(SaturnName.KEY_NODE_ATTRIBUTE_END.equals(super.getNodeAttributeValue(end, SaturnName.XML_TYPE))){
				SaturnEndNode endNode = new SaturnEndNode();
				endNode.setDescription(super.getNodeElementValue(end, Shape.KEY_NODE_DESCRIPTION));
				endNode.setId(super.getNodeAttributeValue(end, Shape.KEY_ATTRIBUTE_ID));
				endNode.setLocation(super.getLocation(end));
				endNode.setLogicList(super.getSaturnAttributeList(end, SaturnName.KEY_NODE_ELEMENT_LOGICKEY,SaturnName.KEY_NODE_NAME_KEY, SaturnName.METHOD_GETKEY));
				endNode.setName(super.getNodeElementValue(end, Shape.KEY_NODE_NAME));
				endNode.setNextId(super.getNodeAttributeValue(end, Shape.KEY_ATTRIBUTE_SHAPE_NEXT_ID));
				endNode.setPolymeMode(super.getNodeElementValue(end, SaturnName.KEY_NODE_ELEMENT_POLYMEMODE));
				endNode.setSize(super.getSize());
				endList.add(endNode);
			}
		}
		return endList;
	}
}
